Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(android,ios): add request headers support #363

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

al1lhomme
Copy link

@al1lhomme al1lhomme commented Dec 4, 2018

Platforms affected

android, ios

What does this PR do?

add request headers support

What testing has been done on this change?

automated test still working
test using headers in my app


closes #361
replaces #115

@janpio janpio changed the title (issue-#361) (iOS & Android) add request headers support (iOS & Android) add request headers support Dec 4, 2018
@janpio

This comment has been minimized.

@ehorodyski
Copy link

Looking for the same thing, will this become a feature in the short term?

@virtualprodigy
Copy link

I would like this feature as well. Any ETAs on this?

@janpio
Copy link
Member

janpio commented Jan 16, 2019

You can help by testing this locally (via the fork of @al1lhomme that contains these changes) and reporting back if it worked as expected.

@metju312
Copy link

Could I ask for progress? This feature is all I need to download any type of files from my server with authentication Header.

hvaughan3 added a commit to hvaughan3/cordova-plugin-inappbrowser that referenced this pull request Apr 30, 2019
@hvaughan3
Copy link

hvaughan3 commented May 1, 2019

@janpio Just merged this into our fork and it seems to be working. It sends headers on the first request and on page reload. Tested on iOS and Android. Did not test using IAB's WKWebView mode.

Copy link
Member

@timbru31 timbru31 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some comments.


Could you also rebase your change?

var strWindowHeaders = '';
if (windowHeaders) {
if (typeof windowHeaders === 'string' || windowHeaders instanceof String) {
strWindowHeaders = windowHeaders.replace(/@/gi, '@a');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what exactly is the reason for all the replacements of @ and = if you just re-replace it in the corresponding Java/Objective-C code?

Wouldn't it be more readable and clearer to pass in a JSON object and then use Android's included JSONObject support to create a HashMap and iOS' included NSJSONSerialization?

@timbru31
Copy link
Member

timbru31 commented Jul 7, 2019

This seems the same as PR #115 - but 3 years newer with fewer conflicts.

@BrandOuellette
Copy link

If this feature will allow us to override the User-Agent header, it would fulfill our feature request #502

@janpio janpio changed the title (iOS & Android) add request headers support feat(android,ios): add request headers support Jul 8, 2019
@janpio
Copy link
Member

janpio commented Jul 8, 2019

Resolved the conflict.

@@ -271,7 +272,7 @@ public void run() {
} else {
((InAppBrowserClient)inAppWebView.getWebViewClient()).waitForBeforeload = false;
}
inAppWebView.loadUrl(url);
inAppWebView.loadUrl(url, null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why all those changes to the loadUrl calls if we don't actually change the method signature ourselves? Couldn't we just keep these as they are and only add the headers in the places where we need it?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this was to explicitely mark headers were null for easier code navigation

@janpio
Copy link
Member

janpio commented Jul 8, 2019

Have to test this for both platforms, and on iOS for both webview types.

Someone have a page handy that shows the headers that were used to call it? Then it should be pretty simple to create a test app.

We should probably also try to add this to the tests somehow.

@BrandOuellette
Copy link

BrandOuellette commented Jul 8, 2019

Someone have a page handy that shows the headers that were used to call it?

https://postman-echo.com/headers

@BrandOuellette
Copy link

BrandOuellette commented Jul 12, 2019

Any update on this?
I really hope we're not waiting on @al1lhomme because it looks like he hasn't been on github for 9 months.

@janpio
Copy link
Member

janpio commented Jul 12, 2019

We will have to find solutions to the comments that are open here. Some questions regarding the code, no new tests, no tested yet.

Anyone who wants to jump in and is not a contributor here (who can edit the fork directly) can just fork at https://github.com/al1lhomme/cordova-plugin-inappbrowser and then create a new PR to this repo and let us know here via a comment.

@jplajpla23
Copy link

how can i use the version with custom headers?

@starnetdev0
Copy link

Hi, I have tested the PullRequest in Android and it works ok.
I have to add a new header to inappbrowser due to the fact that Google will block Google # on January 4, 2021 from embedded browser frameworks.
https://developers.googleblog.com/2020/08/guidance-for-our-effort-to-block-less-secure-browser-and-apps.html

Surprisingly, adding the new header "Google-Accounts-Check-OAuth-Login:true", Google Sign seems to be working. I am using browserTarget: '_blank'

@BradCB
Copy link

BradCB commented Nov 24, 2020

I have tested and used the PullRequest in Android and iOS. Headers are working.

@trafficteam7
Copy link

I have tested and used the PullRequest in Android and iOS. Headers are working.

Doesn't work for me. Tested with Cordova Android 9.0.0. Made all changes in InAppBrowser.java, inappbrowser.js and index.js
By the way: I have 3 files with name InAppBrowser.java - which one should I edit?

@Aiuspaktyn
Copy link

Any news about this PR?

@laurentperez
Copy link

Can confirm this works on Android 10, we did not try to patch iOS because our ionic wrapper uses SafariWebviewController and not InAppBrowser

thx @al1lhomme

@karimaziz
Copy link

Helllo guys, any news on this PR? It's been pending since 2018... Being able to pass headers is quite important and useless for several cases...

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

adding support for passing request headers